/*
n m
a[n]
p[n]%MOD

(a[i]*b[j])modc[t]
*/
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;
#define mod(x) ((x+MOD)%MOD)

#define DEBUG
inline int read()
{
    int c=getchar(), f=1, x=0;
    if(c=='-') f*=-1, c=getchar();
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    return f*x;
}

inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}

const int N=1e5+10, M=1000, MOD=998244853;
int n, m;
int a[N], p[N];
// ll dp[N][M]; //dp[i][j]:前i道题最终得分取模后为j的概率
ll dp[M]; //线性优化
ll tmp[M];

long long qmi(ll base, ll index)
{
    ll res=1;
    while(index)
    {
        if(index&1) res=res*base%MOD;
        base=base*base%MOD;
        index>>=1;
    }
    return res;
}

void init()
{
    n=read(), m=read();
    for(int i=1; i<=n; i++) a[i]=read();
    for(int i=1; i<=n; i++) p[i]=read();

    // for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    // for(int i=1; i<=n; i++) scanf("%d", &p[i]);
}

void solve()
{
    init();
    dp[0]=1; //0道题 分数一定为0
    for(int i=1; i<=n; i++)
    {
        memset(tmp, 0, sizeof tmp); //dp[i][j] dp[j]:dp[i-1][j]
        for(int j=0; j<m; j++)
        {
            // //做错
            // dp[i][j]=mod(dp[i][j]+mod(dp[i-1][j]*mod(1-p[i]))); //分数不变，考虑累加
            // //做对
            // dp[i][(j+a[i])%m]=mod(dp[i][(j+a[i])%m]+mod(dp[i-1][j]*p[i]));
            
            // tmp[j]=mod(tmp[j]+mod(dp[j]*mod(1-p[i])));
            // tmp[(j+a[i])%m]=mod(tmp[(j+a[i])%m]+mod(dp[j]*p[i]));

            // 做错第 i 道题
            tmp[j] = (tmp[j] + dp[j] * (MOD + 1 - p[i]) % MOD) % MOD;
            // 做对第 i 道题
            int next = (j + a[i]) % m;
            tmp[next] = (tmp[next] + dp[j] * p[i] % MOD) % MOD;
        }
        memcpy(dp, tmp, sizeof dp);
    }
        
    write(dp[0]); puts("");
    // debug();
}

signed main()
{

    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    int T=1; //cin >> T; 
    while(T--) 
    {
        solve();
    }
    return 0;
}